package main

import (
	"fmt"
	"time"
)

func producer(out chan<- int) {
	for i := 0; i < 20; i++ {
		fmt.Println("生产：", i)
		out <- i
	}
	close(out)
}
func consumer(in <-chan int) {
	for num := range in {
		time.Sleep(time.Second)
		fmt.Println("消费者拿到：", num)
	}
}
func main() {
	ch := make(chan int, 30)
	go producer(ch) // 子go程 生产者
	consumer(ch)    // 主go程 消费
}
